﻿using Furion;
using Microsoft.Extensions.DependencyInjection;
using SqlSugar;

namespace ASY.Core;

public static class SqlsugarSetup
{
    public static void AddSqlsugarSetup(this IServiceCollection services)
    {
        var sqlSugar = BootstrapClient.DataAccess.SqlSugar.DbContext.Instance;
        services.AddSingleton<ISqlSugarClient>(sqlSugar);
#if DEBUG
        InitcomDb(sqlSugar);
#endif
    }

    public static void InitcomDb(SqlSugarScope sqlSugar)
    {
        var types = App.EffectiveTypes.Where(u => !u.IsInterface && !u.IsAbstract && u.IsClass && u.IsDefined(typeof(SugarTable), false)).ToList();
        //指定当方法 (在当前方法加上这行，这个方法里面会生效)
        sqlSugar.CurrentConnectionConfig.MoreSettings = new ConnMoreSettings()
        {
            DisableNvarchar = true,
            SqlServerCodeFirstNvarchar = true,
        };
        sqlSugar.CodeFirst.SetStringDefaultLength(200).InitTables(types.ToArray());
    }
}
